package com.lijy.superseckill.repository;

import com.lijy.superseckill.domain.User;
import org.springframework.stereotype.Repository;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;


/**
 * {@link User} {@link Repository}
 */
@Repository
public class UserRepository {
    private final ConcurrentHashMap<Integer, User> repository = new ConcurrentHashMap<>();
    private final static AtomicInteger idG = new AtomicInteger();

    /**
     *
     * @param user {@link User}
     * @return
     */
    public boolean save(User user) {

        Integer id =  idG.incrementAndGet();
        user.setId(id);
        return repository.put(id, user) == null;
    }

}
